package org.example.onlineEducation.entity;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import lombok.Data;

/**
 * permission
 * @author 
 */
@Data
public class Permission implements Serializable {
    private Integer id;

    private String href;

    private String remark;

    private String name;

    private Set<String> roleIds;

    private static final long serialVersionUID = 1L;

    private void setRoleIds(Integer roleId){
        roleIds = new HashSet<>();
        roleIds.add(String.valueOf(roleId));
    }
    public void addRoles(Set<String> set){
        this.roleIds.addAll(set);
    }

    //该方法为核心，勿动
    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        Permission other = (Permission) that;

        if(this.id == other.id){
            other.addRoles(this.getRoleIds());
            return true;
        }

        return false;
    }

    @Override
    public int hashCode() {
        return ((Integer) id).hashCode();
    }


    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", id=").append(id);
        sb.append(", href=").append(href);
        sb.append(", remark=").append(remark);
        sb.append(", name=").append(name);
        sb.append(", serialVersionUID=").append(serialVersionUID);
        sb.append("]");
        return sb.toString();
    }
}